﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Content/Master.Master" Inherits="System.Web.Mvc.ViewPage<SCS.Core.ViewModels.UserViewModels>" %>
<%@ Import Namespace="SCS.Core" %>
<%@ Import Namespace="SCS.Core.Models" %>
<%@ Import Namespace="SCS.Core.ViewModels" %>
<%@ Import Namespace="SCS.Core.Controllers" %>
<%@ Import Namespace="SCSService" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Danh sách tài khoảng
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/javascript">

        function SaveStatus(dropDownList, id) {
            var selectedReport = dropDownList.options[dropDownList.selectedIndex];
            var selects = selectedReport.value;
            actionChangeStatus(selects, id);
        }
        function actionChangeStatus(values, id) {
            var url = '<%=Url.Action("ChangeUserStatus","User")%>' + '/' + id + '/' + values;
            $.getJSON(url, function (outStr) {
                $('#statusID' + id).val(outStr);
            });
        }
        function actionResetPassword(id) {
            var url = '<%=Url.Action("ResetPassword","User")%>' + '/' + id;
            $.getJSON(url, function (outStr) {
                //$('#statusID' + id).val(outStr);
                alert(outStr);
            });
        } 
</script> 
     <% using (Html.BeginForm("ListUsers", "User", FormMethod.Post, new { UserName = "sendFileForm", Email = "sendFileForm", UserStatus = "sendFileForm", enctype = "multipart/form-data" }))
        {%>
    <div class="clear"></div>
    <div class="column full">
    <div class="box ">
		<h2 class="box-header">	Danh sách người dùng </h2>
		<div class="box-content">

                    <div id="grid">
        
		                <div style="float:right; margin:10px;"> 
                          <%= Html.ActionLink("Tạo người dùng mới", "CreateUser", null, new { @class = "button themed" })%>
                        </div>	
				    						               
				               <table class="display" id="tabledata" >
                                <thead>
					                <tr>
						                <th>
                                             <a href="#" class="<%= UserController.GetGridThClass(ViewData, "UserID") %>" 
										                onclick="<%= UserController.GetGridThOnClick(ViewData, "UserID")%>">
								                Mã tài khoản</a>
                                        </th>                                        					               
						                <th>
							                <a href="#" class="<%= UserController.GetGridThClass(ViewData, "UserName") %>" 
										                onclick="<%= UserController.GetGridThOnClick(ViewData, "UserName")%>">
								                Tên tài khoản</a>
						                </th>
						
                                        <th>
                                            <a href="#" class="<%= UserController.GetGridThClass(ViewData, "Email") %>" 
										                onclick="<%= UserController.GetGridThOnClick(ViewData, "Email")%>">
								                Email</a>                                        
                                        </th>
                                 		
                                        <th>
                                            Trạng thái                                    
                                        </th>		
                                        							                
                                        <th>
                                              Quyền
                                        </th>                                  
                                        
                                        <th></th>
					                </tr>
                              
                                </thead>
                                <% if (Model.UserItems.Count() == 0) { %>
			                        <tbody>
                                        <tr>
                                            <td colspan="6">
                                              Không tìm thấy 
                                            </td>
                                        </tr>
                                    </tbody>
		                        <% }
                             else 
                                { %>
                                <tbody>
					                <% foreach (var item in Model.UserItems)
                                    { %>
				                        
						                <tr>						                
                                            <td>
                                                <%= Html.Encode(item.UserID) %>
                                            </td>
							                <td>
								                <%= Html.Encode(item.UserName) %>
							                </td>														               
											
                                            <td>
                                                <%=Html.Encode(item.Email) %>                                                
                                            </td>

                                            <td>
                                                <%
                                                    bool newStatus=false;
                                                    if (item.UserStatus == 0)
                                                    {
                                                        newStatus=true;
                                                    }
                                                    else if (item.UserStatus == 1)
                                                    {
                                                        newStatus=false;
                                                    }
                                                %>
                                                <%
                                                List<SelectListItem> statusDrop = new List<SelectListItem>();
                                                statusDrop.AddRange(new SelectListItem[] { 
                                                new SelectListItem{Selected=newStatus, Text = "Kích hoạt", Value = "1" },
                                                new SelectListItem{Selected=newStatus, Text = "Không kích hoạt", Value = "0" }
                                                });
                                                %>
                                              
                                               <%= Html.DropDownList("statusID" + item.UserID, statusDrop, new { onchange = "SaveStatus(this," + item.UserID + ")" })%>
                                            </td>
                                           
                                           <td>
                                                <% 
                                                    string roleName = "";
                                                    if (item.RoleID != null)
                                                    {
                                                        roleName = UserModel.GetRoleByID((int)item.RoleID).RoleName;
                                                    }
                                                %>
                                                <%=roleName %>
                                           </td>
                                            
                                            <td> 
                                                
                                               <a href="#" onclick="actionResetPassword(<%=item.UserID %>);" >Lấy lại mật khẩu</a> | 
                                               <%--<%= Html.ActionLink("Cập nhật", "EditUser", new { id = item.UserID })%>--%>
                                                <span class="button white"> <%= Html.ActionLink(" ", "EditUser", new { id = item.UserID }, new { @class = "icon_single edit", style = "color:#f7a468;" })%></span>	<!--cap nhat--> | 
                                                								                
                                                <%
                                                    string returnUrl = Request.Url.ToString();
                                                 %>
                                                <%--<%= Html.ActionLink("Xóa", "DeleteUser", new { id = item.UserID, returnUrl = returnUrl }, new { onclick = "return confirm('Bạn muốn xóa tài khoản mã:" + item.UserName + " ?');" })%>--%>
                                                <span class="button white"><%= Html.ActionLink(" ", "DeleteUser", new { id = item.UserID, returnUrl = returnUrl }, new { @class = "icon_single cancel", style = "color:#cc0000;", onclick = "return confirm('Bạn thực sự muốn xóa?');" })%></span>
                                            </td>
						                </tr>

                                             
					                <% } %>
					            </tbody>
                                 <% } %>
				                </table>
			                <!-- data -->
                              <%--  <% if (Model.UserItems.Count() > 0)
                                   { %>
			                       <% Html.RenderPartial("~/Views/Commont/Paging.ascx"); %>
		                        <% } %>--%>
		               
	                </div>  <!-- grid -->	
                
               
	    </div>
	</div>
    <div class="clear"></div>
    </div>    
    <% } %>

</asp:Content>
